package com.smap.core;

/**
 * a coordinate class
 *
 * @author shen
 */
public class XY {

	public static double TOLERANCE = 0;

	public double x;
	public double y;

	public XY() {
		this(0.0, 0.0);
	}

	public XY(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public XY(XY c) {
		this(c.x, c.y);
	}

	public XY move(XY offset) {
		x += offset.x;
		y += offset.y;
		return this;
	}

	@Override
	public String toString() {
		return x + " " + y;
	}

	public XY clone() {
		return new XY(x, y);
	}

	public double distance(XY coord2) {
		double pointX = this.x - coord2.x;
		double pointY = this.y - coord2.y;
		double distance = Math.sqrt((pointX) * (pointX) + (pointY) * (pointY));
		return distance;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof XY) {
			XY xy2 = (XY) obj;
			if (this == xy2) {
				return true;
			} else if ((this.x == xy2.x) && (this.y == xy2.y)) {
				return true;
			} else if ((Math.abs(this.x - xy2.x) < TOLERANCE)
					&& (Math.abs(this.y - xy2.y) < TOLERANCE)) {
				return true;
			}
		}
		return false;
	}
}
